/*
 * logic.h
 *
 *  Created on: 2012.12.30.
 *      Author: Sunshineprincess
 */

#ifndef LOGIC_H_
#define LOGIC_H_

#define SPEED_NORMAL 8
#define SPEED_SLOW	4

/* Obstacle state speed*/
#define SPEED_OBSTACLE				4
/* Parking state speeds */
#define SPEED_PARKING_ENTER			6
#define SPEED_PARKING_OUT 			4
#define SPEED_PARKING_BACKWARD		4
#define SPEED_PARKING_EXIT			5
/* Change lane speed */
#define SPEED_CHANGE_LANE			6
/* Wall tracking speed */
#define SPEED_WALL_TRACKING			6
#define SPEED_FINISH				10


#define STATE_START 0x00
#define STATE_LINETRACK_NORMAL 0x01
#define STATE_CHANGE_LANE 0x02
#define STATE_MISSING_LINE 0x04
#define STATE_NO_LINE_WALL 0x08
#define STATE_OBSTACLE 0x10
#define STATE_INIT 0x20
#define STATE_FINISH 0x40
#define STATE_PARKING 0x80

#define WALL_DETECT_TIMEOUT 5
#define WALL_DETECT_LIMIT 20.0f
#define WALL_LEFT 1
#define WALL_RIGHT 2
#define WALL_BOTH 3

#define LINE_THRESHOLD 3
#define CROSS_LINE_TIMEOUT 1

#define ZERO_DETECT_TIMEOUT 25

#define ABS(x) (x<0 ? -x: x)

void Logic(void);

#endif /* LOGIC_H_ */
